/**   
 * @Title: LotteryRecordDetailAct.java 
 * @Package: com.esun.rabbit2.viewer.mainact.mylotteryact 
 * @Description: (购彩记录详情) 
 * @Author: Billy qigs@500wan.com   
 * @Date: 2011-6-28 下午03:52:58  
 * Copyright (C) 2011 Shenzhen E-sun Sky Net Technology Co.,ltd.
 */
package com.esun.rabbit2.viewer.mainact.mylotteryact.lotteryrecord;

import java.util.ArrayList;
import java.util.HashMap;
import android.app.Activity;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.esun.config.Config;
import com.esun.config.Key;
import com.esun.config.Language;
import com.esun.model.DaletouInfo;
import com.esun.model.HemaiDetailInfo;
import com.esun.model.LotteryRecordDetailInfo;
import com.esun.model.ShuangseqiuInfo;
import com.esun.model.UserInfo;
import com.esun.network.ConnectionChangeReceiver;
import com.esun.rabbit2.communicaters.CheDanCommunicater;
import com.esun.rabbit2.communicaters.GetUserIconCommunicater;
import com.esun.rabbit2.communicaters.LotteryRecordDetailCommunicater;
import com.esun.rabbit2.viewer.mainact.lotteryhallact.DaletouAgp;
import com.esun.rabbit2.viewer.mainact.lotteryhallact.ShuangseqiuAgp;
import com.esun.rabbit2.viewer.mainact.lotteryhallact.daletouagp.DaletouChooseAct;
import com.esun.rabbit2.viewer.mainact.lotteryhallact.shiyixuanwu.ShiyixuanwuActGroup;
import com.esun.rabbit2.viewer.mainact.lotteryhallact.shiyixuanwu.ShiyixuanwuChooseOkList;
import com.esun.rabbit2.viewer.mainact.lotteryhallact.shiyixuanwu.rabbittrunk.ShiyixuanwuPlayStyle;
import com.esun.rabbit2.viewer.mainact.lotteryhallact.shuangseqiuagp.ShuangseqiuChooseAct;
import com.esun.ui.R;
import com.esun.util.ShowZhanji;
import com.esun.util.ViewerUtil;
import com.esun.util.img.ImageUtils;
import com.esun.util.img.db.ImageDB;
import com.esun.util.log.EDebug;

/**
 * @ClassName: LotteryRecordDetailAct
 * @Description: (购彩记录详情)
 * @Author: Billy qigs@500wan.com
 * @Date: 2011-6-28 下午03:52:58
 */
public class LotteryRecordDetailAct extends Activity implements OnClickListener {
	private Bundle bundle;
	private ImageButton btnBack;// 返回按钮
	private Button btnCheDan;// 撤单按钮
	private Button btnContinueBuy;
	private Button btnShowMore;// 显示更多按钮
	private TextView tvLotName, tvLotteryDate, tvProID;
	private TextView tvUserName, tvWinCount, tvAllWinMoney;
	private TextView tvProMoney_DaiGou;
	private TextView tvBeiShu_DaiGou, tvFenShu_DaiGou, tvEachMoney_DaiGou, tvBuyProgress_DaiGou, tvIssuc_DaiGou;
	private TextView tvAllMoney_HeMai, tvBeiShu_HeMai, tvFenShu_HeMai, tvEachMoney_HeMai, tvBaoDiMoney_HeMai;
	private TextView tvTiCheng_HeMai, tvIsManYuan_HeMai, tvBuyProgress_HeMai, tvLeftNumber_HeMai;
	private TextView tvOpenCodeRed, tvOpenCodeBlue;
	private TextView tvLotteryState, tvWinMoney, tvSYXWAllMoney, tvSYXWIssuc;
	private LinearLayout linearDaiGou, linearHeMai;
	private LinearLayout linearContent;
	private LinearLayout linearZhanJi, linearMoneyNum, linearSYXW, linearCheDan;
	// private ImageView imageJinZuan, imageJinXing, imageYinZuan, imageYinXing;
	private LotteryRecordDetailCommunicater lotteryRecordCommunicater;
	private GetUserIconCommunicater getUserIconCommunicater;
	private Handler handlerGetLotteryRecordDetail;
	private ProgressDialog progressDialog;
	private ImageView imageFaqiren;
	private CheDanCommunicater cheDanCommunicater;
	private String lotID, pID;
	private String serverMessage;
	private String lotid;
	private String lotName;
	private String id;
	private String proid;
	private String playID;
	private String winMoney;
	private String uid;
	private String ishm;
	private String opencode;
	private String fauserName;
	private String TXTURL;
	private String[] strContent;
	private final int GET_LOTTERYRECORDDETAIL_SUCCEED = 1001; // 获取详情通信成功、失败
	private final int GET_LOTTERYRECORDDETAIL_FAIL = 1002;
	private final int CHEDAN_SUCCEED = 1003; // 撤单通信成功、失败
	private final int CHEDAN_FAIL = 1004;
	private static final int REPLACE_IMAGE = 1006;
	private static final int GET_ICONNAME_SUCCEED = 1007;
	private static final int GET_ICONNAME_FAIL = 1008;
	private static final int BTN_SHOW_TXT_ID = 1009;
	private static final int BTN_SHOW_MORE_ID = 1010;
	private final String FLAG_TXT = "txt";
	private Intent intent;
	private boolean isTXT;

	// private ImageZhanJi imageZhanJi;
	// 显示战绩星级的linear
	private LinearLayout linearstar;

	/** 战绩计算参数 */
	// private static final int INTEGER_WUSHI = 50;
	// private static final int INTEGER_YIBAI = 100;

	// private int integer_JinZuanMax = INTEGER_WUSHI;

	/** 2011-11-16 city add */
	private Button btnReBuy;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.lotteryrecord_detail_act);

		initUI();
		initHandler();
	}

	// 初始化
	public void initUI() {

		progressDialog = ViewerUtil.showProgressDialog(LotteryRecordDetailAct.this, getResources().getString(R.string.loading_text));

		bundle = this.getIntent().getExtras();
		lotid = bundle.getString("lotid");
		id = bundle.getString("id");
		proid = bundle.getString("proid");
		if (bundle.getString("uid") != null) {
			uid = bundle.getString("uid");
		} else {
			uid = bundle.getString("id");
		}
		winMoney = bundle.getString("winMoney");

		imageFaqiren = (ImageView) findViewById(R.id.lotteryrecord_detailact_image_userHead);
		// imageZhanJi = new ImageZhanJi();

		btnBack = (ImageButton) findViewById(R.id.lotteryrecord_detailact_btn_back);
		btnBack.setOnClickListener(this);

		btnCheDan = (Button) findViewById(R.id.lotteryrecord_detailact_btn_cheDan);
		btnCheDan.setOnClickListener(this);

		btnContinueBuy = (Button) findViewById(R.id.lotteryrecord_detailact_btn_continueBuy);
		btnContinueBuy.setOnClickListener(this);

		btnShowMore = new Button(LotteryRecordDetailAct.this);

		tvLotName = (TextView) findViewById(R.id.lotteryrecord_detailact_tv_lotId);

		tvLotteryDate = (TextView) findViewById(R.id.lotteryrecord_detailact_tv_lotteryTime);
		tvProID = (TextView) findViewById(R.id.lotteryrecord_detailact_tv_proid);

		tvUserName = (TextView) findViewById(R.id.lotteryrecord_detailact_tv_userName);
		tvWinCount = (TextView) findViewById(R.id.lotteryrecord_detailact_tv_winCount);
		tvAllWinMoney = (TextView) findViewById(R.id.lotteryrecord_detailact_tv_winMoney);

		tvProMoney_DaiGou = (TextView) findViewById(R.id.lotteryrecord_detailact_tv_proMoneyDaiGou);
		tvBeiShu_DaiGou = (TextView) findViewById(R.id.lotteryrecord_detailact_tv_beiShuDaiGou);
		tvFenShu_DaiGou = (TextView) findViewById(R.id.lotteryrecord_detailact_tv_fenShuDaiGou);
		tvEachMoney_DaiGou = (TextView) findViewById(R.id.lotteryrecord_detailact_tv_eachMoneyDaiGou);
		tvBuyProgress_DaiGou = (TextView) findViewById(R.id.lotteryrecord_detailact_tv_buyProgressDaiGou);
		tvIssuc_DaiGou = (TextView) findViewById(R.id.lotteryrecord_detailact_tv_IssucDaiGou);

		tvAllMoney_HeMai = (TextView) findViewById(R.id.lotteryrecord_detailact_tv_allMoneyHeMai);
		tvBeiShu_HeMai = (TextView) findViewById(R.id.lotteryrecord_detailact_tv_beiShuHeMai);
		tvFenShu_HeMai = (TextView) findViewById(R.id.lotteryrecord_detailact_tv_fenShuHeMai);
		tvEachMoney_HeMai = (TextView) findViewById(R.id.lotteryrecord_detailact_tv_eachMoneyHeMai);
		tvBaoDiMoney_HeMai = (TextView) findViewById(R.id.lotteryrecord_detailact_tv_baoDiMoneyHeMai);
		tvTiCheng_HeMai = (TextView) findViewById(R.id.lotteryrecord_detailact_tv_tiChengHeMai);
		tvIsManYuan_HeMai = (TextView) findViewById(R.id.lotteryrecord_detailact_tv_isManYuanHeMai);
		tvBuyProgress_HeMai = (TextView) findViewById(R.id.lotteryrecord_detailact_tv_buyProgressHeMai);
		tvLeftNumber_HeMai = (TextView) findViewById(R.id.lotteryrecord_detailact_tv_leftNumberHeMai);

		tvLotteryState = (TextView) findViewById(R.id.lotteryrecord_detailact_tv_lotteryState);
		tvWinMoney = (TextView) findViewById(R.id.lotteryrecord_detailact_tv_getMoney);
		tvSYXWAllMoney = (TextView) findViewById(R.id.lotteryrecord_detailact_tv_syxwAllMoney);
		tvSYXWIssuc = (TextView) findViewById(R.id.lotteryrecord_detailact_tv_syxwIssuc);
		tvOpenCodeRed = (TextView) findViewById(R.id.lotteryrecord_detailact_tv_opencodeRed);
		tvOpenCodeBlue = (TextView) findViewById(R.id.lotteryrecord_detailact_tv_opencodeBlue);

		linearDaiGou = (LinearLayout) findViewById(R.id.lotteryrecord_detailact_linear_daiGou);
		linearHeMai = (LinearLayout) findViewById(R.id.lotteryrecord_detailact_linear_heMai);
		linearZhanJi = (LinearLayout) findViewById(R.id.lotteryrecord_detailact_linear_zhanJi);
		linearMoneyNum = (LinearLayout) findViewById(R.id.lotteryrecord_detailact_linear_moneyNum);
		linearSYXW = (LinearLayout) findViewById(R.id.lotteryrecord_detailact_linear_syxw);
		linearCheDan = (LinearLayout) findViewById(R.id.lotteryrecord_detailact_linear_five);
		linearContent = (LinearLayout) findViewById(R.id.lotteryrecord_detailact_linear_content);
		linearstar = (LinearLayout) findViewById(R.id.lotteryrecord_detailact_linear_stars);
		// imageJinZuan = (ImageView) findViewById(R.id.lotteryrecord_detail_image_jinzuan);
		// imageJinXing = (ImageView) findViewById(R.id.lotteryrecord_detail_image_jinxing);
		// imageYinZuan = (ImageView) findViewById(R.id.lotteryrecord_detail_image_yinzuan);
		// imageYinXing = (ImageView) findViewById(R.id.lotteryrecord_detail_image_yinxing);

		/** 2011-11-16 city add */
		btnReBuy = (Button) findViewById(R.id.lotteryrecord_detailact_btn_continueBuy);
		btnReBuy.setOnClickListener(this);

		lotID = lotid;
		if (lotid.equals("45")) {
			pID = uid;
			lotName = "11选5";
			TXTURL = Config.TXTURLSYXW;
			linearSYXW.setVisibility(View.VISIBLE);
			linearZhanJi.setVisibility(View.GONE);
			linearMoneyNum.setVisibility(View.GONE);
		} else {
			pID = id;
			if (lotid.equals("3")) {
				lotName = "双色球";
				TXTURL = Config.TXTURLSSQ;
				// integer_JinZuanMax = INTEGER_WUSHI;
			} else if (lotid.equals("28")) {
				lotName = "大乐透";
				TXTURL = Config.TXTURLDLT;
				// integer_JinZuanMax = INTEGER_YIBAI;
			} else if (lotid.equals(Config.JINGCAIZUQIU)) {
				lotName = "竞彩足球";
			} else if (lotid.equals(Config.FUCAI3D)) {
				lotName = "福彩3D";
				TXTURL = Config.TXTURLFUCAI3D;
			}
		}

		progressDialog.show();

		getLotteryRecordDetailThread();
	}

	// 获取详细信息线程
	public void getLotteryRecordDetailThread() {
		new Thread() {

			@Override
			public void run() {
				// TODO Auto-generated method stub
				lotteryRecordCommunicater = new LotteryRecordDetailCommunicater();
				Message msg;
				try {
					EDebug.o(this, "pid" + pID);
					boolean isSucceed = lotteryRecordCommunicater.isGetLotteryRecordDetail(lotID, pID);
					if (isSucceed) {
						msg = handlerGetLotteryRecordDetail.obtainMessage(GET_LOTTERYRECORDDETAIL_SUCCEED, null);
					} else {
						msg = handlerGetLotteryRecordDetail.obtainMessage(GET_LOTTERYRECORDDETAIL_FAIL, null);
					}
					serverMessage = lotteryRecordCommunicater.getServerMsg();
					handlerGetLotteryRecordDetail.sendMessage(msg);
				} catch (Exception e) {
					msg = handlerGetLotteryRecordDetail.obtainMessage(Config.CONNECTION_FAIL, null);
					handlerGetLotteryRecordDetail.sendMessage(msg);
				}
			}
		}.start();
	}

	// 通讯结果处理
	public void initHandler() {
		handlerGetLotteryRecordDetail = new Handler() {

			@Override
			public void handleMessage(Message msg) {
				// TODO Auto-generated method stub
				super.handleMessage(msg);
				switch (msg.what) {
				case GET_LOTTERYRECORDDETAIL_SUCCEED:
					communicaterSucceed(lotteryRecordCommunicater.getLotteryRecordDetail());
					break;

				case GET_LOTTERYRECORDDETAIL_FAIL:
					ViewerUtil.showTipDialog(LotteryRecordDetailAct.this, serverMessage, false);
					break;

				case CHEDAN_SUCCEED:
					EDebug.o(this, "撤单成功");
					UserInfo.getUserInfo().setUserBalance(cheDanCommunicater.getMoney());
					ViewerUtil.showTipDialog(LotteryRecordDetailAct.this, "撤单成功", false);
					break;

				case CHEDAN_FAIL:
					EDebug.o(this, "撤单失败");
					ViewerUtil.showTipDialog(LotteryRecordDetailAct.this, serverMessage, false);
					break;

				case Config.CONNECTION_FAIL:
				  
					//ViewerUtil.showTipDialog(LotteryRecordDetailAct.this, Language.STR_CONNECTIONFAIL, false);
					Toast.makeText(LotteryRecordDetailAct.this, Language.STR_CONNECTIONFAIL, 0).show();
					break;

				case REPLACE_IMAGE:
					Bitmap bm = (Bitmap) msg.obj;
					imageFaqiren.setImageBitmap(bm);

					break;

				case GET_ICONNAME_SUCCEED:
					getAvatar();
					break;

				case GET_ICONNAME_FAIL:
					EDebug.o(LotteryRecordDetailAct.this, "get icon name fail");
					break;

				default:
					break;
				}
				progressDialog.dismiss();
			}
		};
	}

	// 数据显示
	public void communicaterSucceed(ArrayList<LotteryRecordDetailInfo> list) {
		if (lotid.equals(Config.JINGCAIZUQIU)) {
			tvLotName.setText(lotName + list.get(0).getPlayName());
		} else {
			tvLotName.setText(lotName + "第" + list.get(0).getExpect() + "期" + list.get(0).getPlayName());
		}
		if (list.get(0).getProID().equals("") || list.get(0).getProID().equals(null)) {
			tvProID.setText(proid);
		} else {
			tvProID.setText(list.get(0).getProID());
		}
		tvLotteryDate.setText(list.get(0).getAddTime());
		playID = list.get(0).getPlayID();
		winMoney = list.get(0).getWinMoney().substring(0, list.get(0).getWinMoney().indexOf(".") + 3);
		tvUserName.setText(list.get(0).getUserName());
		fauserName = list.get(0).getUserName();
		threadGetUserIcon();// 获取用户头像
		tvAllWinMoney.setText("￥" + list.get(0).getLotteryMoney());
		tvWinCount.setText(list.get(0).getLotteryCount() + "次");
		if (list.get(0).getState().equals("0")) {
			tvLotteryState.setText(Language.MSG_DENGDAIKAIJIANG);
		} else if (list.get(0).getState().equals("1")) {
			tvLotteryState.setText("未算奖");
		} else if (list.get(0).getState().equals("2")) {
			tvLotteryState.setText("未中奖");
		} else if (list.get(0).getState().equals("3")) {
			tvLotteryState.setText("未派奖");
		} else if (list.get(0).getState().equals("4")) {
			tvLotteryState.setText("已派奖");
			tvWinMoney.setVisibility(View.VISIBLE);
			tvWinMoney.setText("￥" + winMoney);
		}
		tvUserName.setText(list.get(0).getUserName());
		tvAllWinMoney.setText("￥" + list.get(0).getLotteryMoney());
		tvWinCount.setText(list.get(0).getLotteryCount() + "次");
		// 是否开奖
		opencode = list.get(0).getOpenCode();
		if (opencode.equals("") || opencode.equals(" ") || opencode.equals(null) || opencode.equals("|")) {
			tvOpenCodeRed.setText("等待开奖");
			tvOpenCodeRed.setTextColor(getResources().getColor(R.color.solid_black));
			tvOpenCodeBlue.setText("");
		} else {
			if (lotid.equals("45")) {
				tvOpenCodeRed.setText(opencode.replace(',', ' '));
				tvOpenCodeBlue.setText("");
			} else if (lotid.equals(Config.FUCAI3D)) {
				tvOpenCodeRed.setText(opencode.replace(',', ' '));
				tvOpenCodeBlue.setText("");
			} else {
				String[] strOpenCode = opencode.split("\\|");
				tvOpenCodeRed.setText(strOpenCode[0].replace(',', ' '));
				tvOpenCodeBlue.setText(strOpenCode[1].replace(',', ' '));
			}
		}
		if (lotid.equals(Config.SHIYIXUANWU)) {
			tvSYXWAllMoney.setText("￥" + list.get(0).getAllMoney());
			if (list.get(0).getIssuc().equals("1")) {
				tvSYXWIssuc.setText("已出票");
			} else {
				tvSYXWIssuc.setText("出票中");
			}
		} else {
			// 是否是合买
			ishm = list.get(0).getIsHm();
			if (ishm.equals("0")) {
				linearDaiGou.setVisibility(View.VISIBLE);
				tvProMoney_DaiGou.setText("￥" + list.get(0).getAllMoney());
				tvBeiShu_DaiGou.setText(list.get(0).getBeiShu() + "倍");
				tvFenShu_DaiGou.setText(list.get(0).getFenShu() + "份");
				tvEachMoney_DaiGou.setText("￥" + list.get(0).getOneMoney());
				tvBuyProgress_DaiGou.setText(list.get(0).getJinDu() + "%");
				if (list.get(0).getIssuc().equals("0")) {
					tvIssuc_DaiGou.setText("出票中");
				} else {
					tvIssuc_DaiGou.setText("已出票");
				}
			} else if (ishm.equals("1")) {
				linearHeMai.setVisibility(View.VISIBLE);
				tvAllMoney_HeMai.setText("￥" + list.get(0).getAllMoney());
				tvBeiShu_HeMai.setText(list.get(0).getBeiShu() + "倍");
				tvFenShu_HeMai.setText(list.get(0).getFenShu() + "份");
				tvEachMoney_HeMai.setText("￥" + list.get(0).getOneMoney());
				tvBaoDiMoney_HeMai.setText("￥" + list.get(0).getBaoDiMoney());
				tvTiCheng_HeMai.setText(list.get(0).getTiCheng() + "%");
				if (list.get(0).getIsManYuan().equals("1")) {
					tvIsManYuan_HeMai.setText("已满员");
				} else {
					tvIsManYuan_HeMai.setText("未满员");
				}
				tvBuyProgress_HeMai.setText(list.get(0).getJinDu() + "%");
				tvLeftNumber_HeMai.setText(list.get(0).getLeftNumber() + "份");

				if (Integer.valueOf(list.get(0).getBaoDi()) + Integer.valueOf(list.get(0).getJinDu()) < 50) {
					linearCheDan.setVisibility(View.VISIBLE);
					btnCheDan.setVisibility(View.VISIBLE);
				}
			}
		}

		// 方案内容
		plmContent = list.get(0).getFileContent();
		// 更多内容传入参数
		strContent = plmContent.replace(",", " ").split("\\$");

		// 是否是本人发起方案
		if (list.get(0).getUserName().equals(UserInfo.getUserInfo().getUserName())) {
			// 是本人发起,可见
			contentJusty(plmContent, list);
		} else {
			// 不是本人发起
			// 判断方案显示方式0-完全公开1-截止后公开2-仅跟单人可见
			if (list.get(0).getIsShow().equals(Config.NUM0) || list.get(0).getIsShow().equals(Config.NUM2)) {
				// 可见
				contentJusty(plmContent, list);
			} else {
				// 截止后公开
				TextView tvOpenAfterEnd = new TextView(LotteryRecordDetailAct.this);
				tvOpenAfterEnd.setText(Language.POPLOTTERYTIP_JIEZHIHOUGONGKAI);
				tvOpenAfterEnd.setGravity(Gravity.CENTER);
				tvOpenAfterEnd.setTextColor(getResources().getColor(R.color.solid_black));
				linearContent.addView(tvOpenAfterEnd);
			}
		}

		zhanJiShow(list);
		/** 2011-11-16 city add */
		if (list.get(0).getUserName().equals(UserInfo.getUserInfo().getUserName()) && !isTXT && !lotid.equals(Config.FUCAI3D)) {
			linearCheDan.setVisibility(View.VISIBLE);
			btnReBuy.setVisibility(View.VISIBLE);
		}
	}

	/**
	 * 判断是否为txt文本方案 content 方案内容 list 详情参数info
	 * */
	private void contentJusty(String content, ArrayList<LotteryRecordDetailInfo> list) {
		// 判断方案内容是否为txt文本
		if (content.contains(FLAG_TXT) && list.get(0).getIsUpload().equals(Config.NUM1)) {
			// 是txt文本并已上传
			isTXT = true;
			btnShowMore.setText("查看上传方案");
			btnShowMore.setId(BTN_SHOW_TXT_ID);
			btnShowMore.setOnClickListener(this);
			linearContent.addView(btnShowMore);

		} else if (content.contains(FLAG_TXT) && list.get(0).getIsUpload().equals(Config.NUM0)) {
			// 是txt文本但并未上传
			isTXT = true;
			TextView tvNoUpload = new TextView(LotteryRecordDetailAct.this);
			tvNoUpload.setText(Language.POPLOTTERYTIP_FANGANWEISHANGCHUAN);
			tvNoUpload.setGravity(Gravity.CENTER);
			tvNoUpload.setTextColor(getResources().getColor(R.color.solid_black));
			linearContent.addView(tvNoUpload);

		} else {
			// 不是txt文本
			isTXT = false;
			if (content.length() != 0 && !content.equals("")) {
				displayMultiContent(content);
			} else {
				TextView tvNoContent = new TextView(LotteryRecordDetailAct.this);
				tvNoContent.setText(Language.POPLOTTERYTIP_WUFANGAN);
				tvNoContent.setGravity(Gravity.CENTER);
				tvNoContent.setTextColor(getResources().getColor(R.color.solid_black));
				linearContent.addView(tvNoContent);
			}
		}
	}

	/**
	 * 显示多条方案内容 content 方案内容
	 * */
	private void displayMultiContent(String content) {
		// 若为11选5 玩法id转换
		if (lotid.equals(Config.SHIYIXUANWU)) {
			content = syxwTransfer(content);
		}
		// 将多条方案拆分
		String[] contentList = content.replace(",", " ").split("\\$");
		// 若为11选5或者福彩3d只显示红球
		if (lotid.equals(Config.SHIYIXUANWU) || lotid.equals(Config.FUCAI3D)) {
			// 如果方案内容少于7条则全部显示
			if (contentList.length >= 0 && contentList.length <= Config.CONTENT_SHOW_MAX_NUM) {
				// 加载每条方案内容
				addContentSingle(contentList, 0, contentList.length);
			} else {
				// 如果方案内容多余7条则只显示前7条并最后加入按钮
				// 加载每条方案内容
				addContentSingle(contentList, 0, Config.CONTENT_SHOW_MAX_NUM);
				btnShowMore.setText("...");
				btnShowMore.setId(BTN_SHOW_MORE_ID);
				btnShowMore.setOnClickListener(this);
				linearContent.addView(btnShowMore);
			}
		} else {
			// 否则拆分红篮球
			// 如果方案内容少于7条则全部显示
			if (contentList.length >= 0 && contentList.length <= Config.CONTENT_SHOW_MAX_NUM) {
				// 加载每条方案内容
				addContentColor(contentList, 0, contentList.length);
			} else {
				// 如果方案内容多余7条则只显示前7条并最后加入按钮
				// 加载每条方案内容
				addContentColor(contentList, 0, Config.CONTENT_SHOW_MAX_NUM);
				btnShowMore.setText("...");
				btnShowMore.setId(BTN_SHOW_MORE_ID);
				btnShowMore.setOnClickListener(this);
				linearContent.addView(btnShowMore);
			}
		}
	}

	/**
	 * 加载单色方案内容 content start end
	 * */
	private void addContentSingle(String[] content, int start, int end) {
		for (int i = start; i < end; i++) {
			if (content[i].length() != 0) {
				// 判断红球有没有超过显示要求最大值6个,超过则做截取
				int red_length = content[i].length();
				if (red_length > Config.RED_MAX_NUM) {
					content[i] = content[i].substring(0, Config.RED_MAX_NUM) + "...";
				}
				TextView tvContent = new TextView(LotteryRecordDetailAct.this);
				tvContent.setText(content[i]);
				tvContent.setTextColor(getResources().getColor(R.color.kjxx_red));
				tvContent.setSingleLine(true);
				tvContent.setPadding(5, 5, 5, 5);
				tvContent.setEllipsize(TextUtils.TruncateAt.END);
				linearContent.addView(tvContent);
			}
		}
	}

	/**
	 * 加载红篮球方案内容 content start end
	 * */
	private void addContentColor(String[] content, int start, int end) {
		for (int i = start; i < end; i++) {
			if (content[i].length() != 0) {
				String[] str = content[i].split("\\|");
				LinearLayout linear = new LinearLayout(LotteryRecordDetailAct.this);
				// 判断红球有没有超过显示要求最大值,超过则做截取
				int red_length = str[0].length();
				if (red_length > Config.RED_MAX_NUM) {
					str[0] = str[0].substring(0, Config.RED_MAX_NUM) + "...";
				}
				// 显示红球
				TextView tvContentRed = new TextView(LotteryRecordDetailAct.this);
				tvContentRed.setText(str[0]);
				tvContentRed.setTextColor(getResources().getColor(R.color.kjxx_red));
				tvContentRed.setTextSize(14);
				tvContentRed.setSingleLine(true);
				tvContentRed.setPadding(5, 5, 5, 5);
				tvContentRed.setEllipsize(TextUtils.TruncateAt.END);
				linear.addView(tvContentRed);
				// 判断红球有没有超过显示要求最大值2个,超过则做截取
				int blue_length = str[1].length();
				if (blue_length > Config.BLUE_MAX_NUM) {
					str[1] = str[1].substring(0, Config.BLUE_MAX_NUM) + "...";
				}
				// 显示蓝球
				TextView tvContentBlue = new TextView(LotteryRecordDetailAct.this);
				tvContentBlue.setText(str[1]);
				tvContentBlue.setTextColor(getResources().getColor(R.color.kjxx_blue));
				tvContentBlue.setTextSize(14);
				tvContentBlue.setSingleLine(true);
				tvContentRed.setPadding(5, 5, 5, 5);
				tvContentBlue.setEllipsize(TextUtils.TruncateAt.END);
				linear.addView(tvContentBlue);
				linearContent.addView(linear);
			}
		}
	}

	/**
	 * 2012-3-15 Kael修改 战绩计算和显示
	 * 
	 */
	public void zhanJiShow(ArrayList<LotteryRecordDetailInfo> list) {
		// 金钻
		String golddiamond = list.get(0).getGoldDiamond();
		// 银钻
		String silverdiamond = list.get(0).getSilverDiamond();
		// 金星
		String goldstar = list.get(0).getGoldStar();
		// 银星
		String silverstar = list.get(0).getSilverStar();
		// 金杯
		String goldcup = list.get(0).getGoldCup();
		EDebug.o("golddiamond", golddiamond);
		EDebug.o("silverdiamond", silverdiamond);
		EDebug.o("goldstar", goldstar);
		EDebug.o("silverstar", silverstar);
		EDebug.o("goldcup", goldcup);
		ShowZhanji zhanji = new ShowZhanji(LotteryRecordDetailAct.this);
		// 获取显示战绩星级图片的list
		ArrayList<ImageView> zhanjilist = new ArrayList<ImageView>();
		zhanjilist = zhanji.showzhanji(golddiamond, silverdiamond, goldstar, silverstar, goldcup);
		// 判断是否有战绩
		int size = zhanjilist.size();
		if (size == 0) {// 没有战绩就不显示战绩的linear
			linearZhanJi.setVisibility(View.GONE);
		} else {// 有战绩就将list中的ImageView添加到显示战绩的linear
			for (int i = 0; i < zhanjilist.size(); i++) {
				linearZhanJi.setVisibility(View.VISIBLE);
				linearstar.setVisibility(View.VISIBLE);
				linearstar.addView(zhanjilist.get(i));
			}
		}

	}

	public void stringShowProcess(String str, LinearLayout linear, TextView tvRed, TextView tvBlue) {
		if (!str.equals("")) {
			linear.setVisibility(View.VISIBLE);
			if (lotid.equals("45")) {
				tvRed.setText(str);
			} else if (lotid.equals(Config.FUCAI3D)) {
				tvRed.setText(str);
			} else {
				String[] strTemp = str.split("\\|");
				if (strTemp[0].length() > 20) {
					tvRed.setText(strTemp[0].substring(0, 20) + "...");
				} else {
					tvRed.setText(strTemp[0]);
				}
				if (strTemp[1].length() > 14) {
					tvBlue.setText(strTemp[1].substring(0, 14) + "...");
				} else {
					tvBlue.setText(strTemp[1]);
				}
			}
			EDebug.o(this, "7");
		}
	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch (v.getId()) {
		case R.id.lotteryrecord_detailact_btn_back:

			LotteryRecordDetailAct.this.finish();

			break;

		case R.id.lotteryrecord_detailact_btn_cheDan:

			btnChenDanOnClick();

			break;

		case BTN_SHOW_TXT_ID:

			intent = new Intent();
			intent.setClass(LotteryRecordDetailAct.this, LotteryRecordDetailMoreAct.class);
			bundle.putString("classify", "web");
			bundle.putString(Key.KEY_LOTID, lotID);
			bundle.putString("detailurl", TXTURL + playID + "&pid=" + pID);
			EDebug.o(this, TXTURL + playID + "&pid=" + pID);
			intent.putExtras(bundle);
			startActivity(intent);

			break;

		case BTN_SHOW_MORE_ID:

			intent = new Intent();
			intent.setClass(LotteryRecordDetailAct.this, LotteryRecordDetailMoreAct.class);
			bundle.putString("classify", "txt");
			bundle.putString(Key.KEY_LOTID, lotID);
			bundle.putStringArray("content", strContent);
			intent.putExtras(bundle);
			startActivity(intent);

			break;

		case R.id.lotteryrecord_detailact_btn_continueBuy:
			reBuy();
			break;

		default:
			break;
		}
	}

	// 撤单通讯线程
	public void cheDanThread() {
		new Thread() {
			@Override
			public void run() {
				// TODO Auto-generated method stub
				cheDanCommunicater = new CheDanCommunicater();
				EDebug.o(this, "进入撤单线程");
				Message msg = new Message();
				try {
					boolean isSucceed;
					EDebug.o(this, "发起人：" + fauserName + "用户：" + UserInfo.getUserInfo().getUserName());
					if (UserInfo.getUserInfo().getUserName().equals(fauserName)) {
						EDebug.o(this, "发起人撤单");
						isSucceed = cheDanCommunicater.userOrderCheDan(lotid, pID, playID);
					} else {
						EDebug.o(this, "跟单人撤单");
						isSucceed = cheDanCommunicater.isCheDan(lotid, uid, playID);
					}
					serverMessage = cheDanCommunicater.getMsgServer();
					if (isSucceed) {
						msg.what = CHEDAN_SUCCEED;
					} else {
						msg.what = CHEDAN_FAIL;
					}
					handlerGetLotteryRecordDetail.sendMessage(msg);
				} catch (Exception e) {
					// TODO Auto-generated catch block
					msg.what = Config.CONNECTION_FAIL;
					handlerGetLotteryRecordDetail.sendMessage(msg);
				}
			}
		}.start();
	}

	// 11选5玩法代码转换
	public String syxwTransfer(String strContent) {
		strContent = strContent.replace("244", "前一直选");
		strContent = strContent.replace("245", "前二直选");
		strContent = strContent.replace("246", "前三直选");
		strContent = strContent.replace("247", "前二组选");
		strContent = strContent.replace("248", "前三组选");
		strContent = strContent.replace("249", "任选二");
		strContent = strContent.replace("250", "任选三");
		strContent = strContent.replace("251", "任选四 ");
		strContent = strContent.replace("252", "任选五");
		strContent = strContent.replace("253", "任选六 ");
		strContent = strContent.replace("254", "任选七");
		strContent = strContent.replace("255", "任选八");
		strContent = strContent.replace("256", "混投");
		strContent = strContent.replace("257", "前二直选全选");
		strContent = strContent.replace("258", "前三直选全选");
		strContent = strContent.replace("259", "前二直选和值");
		strContent = strContent.replace("260", "前二组选和值");
		strContent = strContent.replace("261", "前二组选胆拖");
		strContent = strContent.replace("262", "前三直选和值");
		strContent = strContent.replace("263", "前三组选和值");
		strContent = strContent.replace("264", "前三组选胆拖");
		strContent = strContent.replace("265", "任选四胆拖");
		strContent = strContent.replace("266", "任选五胆拖");
		strContent = strContent.replace("267", "任选六胆拖");
		strContent = strContent.replace("268", "任选七胆拖");
		strContent = strContent.replace("278", "任选二胆拖");
		strContent = strContent.replace("279", "任选三胆拖");
		strContent = strContent.replace("280", "任选八胆拖");

		return strContent;
	}

	private Boolean isHaveDantuo = false;

	private void updataShiyixuanwuInfo(String lotId) {
		isHaveDantuo = false;
		if (lotId.equals("244")) {
			// 前一直选
			ShiyixuanwuPlayStyle.getPlayStyle().setStyle(1);
			ShiyixuanwuPlayStyle.getPlayStyle().setDetail(2);
		} else if (lotId.equals("249")) {

			// 任选二
			ShiyixuanwuPlayStyle.getPlayStyle().setStyle(2);
			ShiyixuanwuPlayStyle.getPlayStyle().setDetail(1);

		} else if (lotId.equals("250")) {

			// 任选三
			ShiyixuanwuPlayStyle.getPlayStyle().setStyle(3);
			ShiyixuanwuPlayStyle.getPlayStyle().setDetail(1);

		} else if (lotId.equals("251")) {

			// 任选四
			ShiyixuanwuPlayStyle.getPlayStyle().setStyle(4);
			ShiyixuanwuPlayStyle.getPlayStyle().setDetail(1);

		} else if (lotId.equals("252")) {

			// 任选五
			ShiyixuanwuPlayStyle.getPlayStyle().setStyle(5);
			ShiyixuanwuPlayStyle.getPlayStyle().setDetail(1);

		} else if (lotId.equals("253")) {

			// 任选六
			ShiyixuanwuPlayStyle.getPlayStyle().setStyle(6);
			ShiyixuanwuPlayStyle.getPlayStyle().setDetail(1);

		} else if (lotId.equals("254")) {

			// 任选七
			ShiyixuanwuPlayStyle.getPlayStyle().setStyle(7);
			ShiyixuanwuPlayStyle.getPlayStyle().setDetail(1);

		} else if (lotId.equals("255")) {

			// 任选八
			ShiyixuanwuPlayStyle.getPlayStyle().setStyle(8);
			ShiyixuanwuPlayStyle.getPlayStyle().setDetail(1);

		} else if (lotId.equals("245") || lotId.equals("257") || lotId.equals("259")) {

			// 前二直选,前二直选全选,前二直选和值
			ShiyixuanwuPlayStyle.getPlayStyle().setStyle(2);
			ShiyixuanwuPlayStyle.getPlayStyle().setDetail(2);

		} else if (lotId.equals("247") || lotId.equals("260")) {

			// 前二组选,前二组选和值
			ShiyixuanwuPlayStyle.getPlayStyle().setStyle(2);
			ShiyixuanwuPlayStyle.getPlayStyle().setDetail(3);

		} else if (lotId.equals("246") || lotId.equals("258") || lotId.equals("262")) {

			// 前三直选,前三直选全选,前三直选和值
			ShiyixuanwuPlayStyle.getPlayStyle().setStyle(3);
			ShiyixuanwuPlayStyle.getPlayStyle().setDetail(2);

		} else if (lotId.equals("248") || lotId.equals("263")) {

			// 前三组选,前三组选和值
			ShiyixuanwuPlayStyle.getPlayStyle().setStyle(3);
			ShiyixuanwuPlayStyle.getPlayStyle().setDetail(3);

		} else {
			isHaveDantuo = true;
		}
	}

	// 撤单按钮点击事件
	public void btnChenDanOnClick() {
		final Dialog chenDanDialog = new Dialog(LotteryRecordDetailAct.this, R.style.dialog);
		chenDanDialog.getWindow().setContentView(R.layout.dialog_doublebutton_lotteryrecord_detail);
		TextView tvChenDanMsg = (TextView) chenDanDialog.getWindow().findViewById(R.id.dialog_doublebutton_tv_msg);
		tvChenDanMsg.setText("确定对认购方案撤单吗？");
		Button btnChenDanYes = (Button) chenDanDialog.getWindow().findViewById(R.id.dialog_doublebutton_btn_yes);
		btnChenDanYes.setText(getResources().getString(R.string.ok));
		btnChenDanYes.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				cheDanThread();
				chenDanDialog.dismiss();
				progressDialog.show();
			}
		});
		Button btnChenDanNo = (Button) chenDanDialog.getWindow().findViewById(R.id.dialog_doublebutton_btn_no);
		btnChenDanNo.setText(getResources().getString(R.string.cancel));
		btnChenDanNo.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				chenDanDialog.dismiss();
			}
		});
		chenDanDialog.show();
	}

	// 获取发起人头像名称
	private void threadGetUserIcon() {
		new Thread() {
			@Override
			public void run() {
				super.run();
				try {
					getUserIconCommunicater = new GetUserIconCommunicater();
					boolean isSucceed = getUserIconCommunicater.isGetIconNameSucced(fauserName);
					if (isSucceed) {
						Message msg = handlerGetLotteryRecordDetail.obtainMessage(GET_ICONNAME_SUCCEED, null);
						handlerGetLotteryRecordDetail.sendMessage(msg);
					} else {
						Message msg = handlerGetLotteryRecordDetail.obtainMessage(GET_ICONNAME_FAIL, null);
						handlerGetLotteryRecordDetail.sendMessage(msg);
					}
				} catch (Exception e) {
					// TODO: handle exception
					EDebug.o(LotteryRecordDetailAct.this, ".....");
					Message msg = handlerGetLotteryRecordDetail.obtainMessage(GET_ICONNAME_FAIL, null);
					handlerGetLotteryRecordDetail.sendMessage(msg);
				}
			}
		}.start();
	}

	// 下载发起人头像
	private void getAvatar() {
		new Thread() {

			@Override
			public void run() {
				super.run();

				Bitmap bm = null;
				String name = HemaiDetailInfo.getHemaiDetailInfo().getUserIcon();
				ImageDB.getImageDB().open(LotteryRecordDetailAct.this);

				bm = ImageUtils.getLocalImg(name);

				if (bm == null) {
					bm = ImageUtils.downLoadImg(name);
					if (bm != null) {
						Message msg = handlerGetLotteryRecordDetail.obtainMessage(REPLACE_IMAGE, bm);
						handlerGetLotteryRecordDetail.sendMessage(msg);
						ImageUtils.saveImg(name, bm);
					}
				} else {
					Message msg = handlerGetLotteryRecordDetail.obtainMessage(REPLACE_IMAGE, bm);
					handlerGetLotteryRecordDetail.sendMessage(msg);
				}
				ImageDB.getImageDB().close();
			}
		}.start();
	}

	@Override
	protected void onPause() {
		// TODO Auto-generated method stub
		super.onPause();
		this.unregisterReceiver(ConnectionChangeReceiver.getConnectionChangeReceiver());
	}

	@Override
	protected void onResume() {
		// TODO Auto-generated method stub
		super.onResume();
		this.registerReceiver(ConnectionChangeReceiver.getConnectionChangeReceiver(), ConnectionChangeReceiver.getIntentFilter());
		if (UserInfo.getUserInfo().isRebuy()) {
			LotteryRecordDetailAct.this.finish();
		}
	}

	/** 2011-11-16 city add 继续购买 */
	private String plmContent;

	private void reBuy() {
		UserInfo.getUserInfo().setRebuy(false);
		if (lotid.equals(Config.SHUANGSEQIU)) {
			ShuangseqiuInfo.getShuangseqiuInfo().getLotteryList().clear();
			String[] strItems = plmContent.split("\\$");
			for (int i = 0; i < strItems.length; i++) {
				String[] strBall = strItems[i].split("\\|");
				HashMap<String, Object> hashMap = new HashMap<String, Object>();
				ShuangseqiuInfo.getShuangseqiuInfo().setRedBallCount((strBall[0].split(Config.COMMA)).length);
				ShuangseqiuInfo.getShuangseqiuInfo().setBlueBallCount((strBall[1].split(Config.COMMA)).length);
				hashMap.put(Key.KEY_BET_COUNT, ShuangseqiuInfo.getShuangseqiuInfo().getBetCount());
				hashMap.put(Key.KEY_RED, strBall[0].replace(Config.COMMA, Config.ONESPACE));
				hashMap.put(Key.KEY_BLUE, strBall[1].replace(Config.COMMA, Config.ONESPACE));
				ShuangseqiuInfo.getShuangseqiuInfo().getLotteryList().add(hashMap);
				ShuangseqiuInfo.getShuangseqiuInfo().setRedBallCount(0);
				ShuangseqiuInfo.getShuangseqiuInfo().setBlueBallCount(0);
			}
			resetShowType();
			startActivity(new Intent(this, ShuangseqiuAgp.class).putExtra(Config.CURRENT_TAB_NUM, 0).putExtra(Config.IS_REBUY, true));
			UserInfo.getUserInfo().setRebuy(true);

		} else if (lotid.equals(Config.DALETOU)) {

			DaletouInfo.getDaletouInfo().getLotteryList().clear();
			String[] strItems = plmContent.split("\\$");
			for (int i = 0; i < strItems.length; i++) {
				String[] strBall = strItems[i].split("\\|");
				HashMap<String, Object> hashMap = new HashMap<String, Object>();
				DaletouInfo.getDaletouInfo().setRedBallCount((strBall[0].split(Config.COMMA)).length);
				DaletouInfo.getDaletouInfo().setBlueBallCount((strBall[1].split(Config.COMMA)).length);
				hashMap.put(Key.KEY_BET_COUNT, DaletouInfo.getDaletouInfo().getBetCount());
				hashMap.put(Key.KEY_RED, strBall[0].replace(Config.COMMA, Config.ONESPACE));
				hashMap.put(Key.KEY_BLUE, strBall[1].replace(Config.COMMA, Config.ONESPACE));
				DaletouInfo.getDaletouInfo().getLotteryList().add(hashMap);
				DaletouInfo.getDaletouInfo().setRedBallCount(0);
				DaletouInfo.getDaletouInfo().setBlueBallCount(0);
			}
			resetShowType();
			startActivity(new Intent(this, DaletouAgp.class).putExtra(Config.CURRENT_TAB_NUM, 0).putExtra(Config.IS_REBUY, true));
			UserInfo.getUserInfo().setRebuy(true);

		} else if (lotid.equals(Config.SHIYIXUANWU)) {
			ShiyixuanwuChooseOkList.getChooseList().reset();
			String[] strItems = plmContent.split("\\$");
			for (int i = 0; i < strItems.length; i++) {
				String[] strIt = strItems[i].split(Config.RIGHT_BR);
				updataShiyixuanwuInfo(strIt[0].substring(1, strIt[0].length()));
				if (isHaveDantuo) {
					break;
				}
				EDebug.o(LotteryRecordDetailAct.this, "lot id is " + strIt[0].substring(1, strIt[0].length()));
				ShiyixuanwuChooseOkList.getChooseList().add(strIt[0].substring(1, strIt[0].length()), strIt[1], 1, 2, String.valueOf(ShiyixuanwuPlayStyle.getPlayStyle().getStyle()),
						String.valueOf(ShiyixuanwuPlayStyle.getPlayStyle().getDetail()));
			}
			if (isHaveDantuo) {
				Toast.makeText(LotteryRecordDetailAct.this, "暂不支持胆拖投注", Toast.LENGTH_SHORT).show();
			} else {
				startActivity(new Intent(this, ShiyixuanwuActGroup.class).putExtra(Config.IS_REBUY, true));
				UserInfo.getUserInfo().setRebuy(true);
			}

		} else {

		}

	}

	private void resetShowType() {
		// ShuangseqiuHemaiAct.showType = 0;
		ShuangseqiuChooseAct.showType = 0;
		DaletouChooseAct.showType = 0;

	}
}